/*************************************************************************
    > File Name: 2.pthread_create.c
    > Author: Ykk
    > Mail: 3393579535@qq.com 
    > Created Time: 2023年05月09日 星期二 20时56分06秒
 ************************************************************************/

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#include<pthread.h>

//线程调度后执行的任务
void *fun(void *arg)
{
	printf("新的线程执行任务 tid: %lu\n",pthread_self());

	return NULL;
}
//第二个线程启动之后的任务
void *fun1(void *arg)
{
	int var = (int)(long)arg;
	printf("线程2 var = %d\n",var);

	return NULL;
}
int main()
{
	int ret = -1;
	pthread_t tid = -1;
	pthread_t tid2 = -1;
	//创建一个线程
	ret = pthread_create(&tid,NULL,fun,NULL);
	if(0 != ret)
	{
		printf("pthread_create failed....\n");
		return 1;
	}
	printf("main thread... tid:%lu\n",pthread_self());

	//创建一个线程
	ret = pthread_create(&tid2,NULL,fun1,(void *)0x3);
	if(0 != ret)
	{
		printf("pthread_create failed....\n");
		return 1;
	}
	printf("main thread2... tid:%lu\n",pthread_self());

	printf("按下回车键主线程退出....\n");
	getchar();
	return 0;
}
